package org.zhadoop.stream.cql.semanticanalyzer.parser.visitor;

import org.antlr.v4.runtime.misc.NotNull;
import org.zhadoop.stream.cql.semanticanalyzer.parser.CQLParser.CaseWhenBodyThenBodyContext;
import org.zhadoop.stream.cql.semanticanalyzer.parser.CQLParser.CaseWhenBodyWhenBodyContext;
import org.zhadoop.stream.cql.semanticanalyzer.parser.CQLParser.CaseWhenElseContext;
import org.zhadoop.stream.cql.semanticanalyzer.parser.context.WhenExpressionContext;

/**
 * when 表达式的遍历
 * @author zwd
 *
 */
public class WhenExpressionVisitor extends AbsCQLParserBaseVisitor<WhenExpressionContext>{

	private WhenExpressionContext context = null;
	
	public WhenExpressionVisitor() {
		context = new WhenExpressionContext();
	}
	
	@Override
	protected WhenExpressionContext defaultResult() {
		return context;
	}
	
	@Override
	public WhenExpressionContext visitCaseWhenBodyWhenBody(@NotNull CaseWhenBodyWhenBodyContext ctx) {
		CaseWhenBodyWhenBodyVisitor visitor = new CaseWhenBodyWhenBodyVisitor();
        context.getWhens().add(visitor.visit(ctx));
        return context;
	}
	
	@Override
	public WhenExpressionContext visitCaseWhenBodyThenBody(@NotNull CaseWhenBodyThenBodyContext ctx) {
		CaseWhenBodyThenBodyVisitor visitor = new CaseWhenBodyThenBodyVisitor();
        context.getThens().add(visitor.visit(ctx));
        return context;
	}
	
	@Override
	public WhenExpressionContext visitCaseWhenElse(@NotNull CaseWhenElseContext ctx) {
		CaseWhenElseVisitor visitor = new CaseWhenElseVisitor();
        context.setElseExpression(visitor.visit(ctx));
        return context;
	}

}
